home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / ScreenSaver / QD3DErrorModule.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  5.6 KB  |  293 lines  |  [TEXT/CWIE]

  1. /*    This is the c file that implements the action for this screen saver.
  2.     See GraphicsModule.c for infomation on how to write your own.
  3.     
  4.     First Version    Andrew Armstrong
  5.     
  6.     © 1995 Berkeley Systems Inc.
  7. */
  8.  
  9. /*
  10. **    TAB SIZE = 4 spaces
  11. */
  12.  
  13. /*
  14. **    TO DO:
  15. **    * handle the case in _Draw where the rendering could fail. Do we View_Sync()?
  16. **    * Multiple monitors
  17. **    * Make the pixmap point right to the screen for Apple HD Accel
  18. **    * Make the sliders work in demo mode
  19. **    * check for the libraries
  20. **    * check version of the libraries
  21. **    * Handle case where they are not installed (draw error message with WWW Address)
  22. **
  23. **    FUTURE DIRECTIONS
  24. **    * cutsie-ass names on the sliders
  25. */
  26.  
  27. #if 0
  28. #pragma mark INCLUDES
  29. #endif
  30.                 
  31. /*
  32. ** PROJECT INCLUDES
  33. */
  34. #include "QD3DErrorModule.h"
  35. #include "Q3ADUtilities.h"
  36. #include "PICTSprite.h"
  37.  
  38. /*
  39. ** ANSI INCLUDES
  40. */
  41. #include <assert.h>
  42. #include <stdlib.h>
  43.  
  44. /*
  45. ** MAC INCLUDES
  46. */
  47. #include <Quickdraw.h>
  48. #include <QDOffscreen.h>
  49. #include <Memory.h>
  50.  
  51. #if 0
  52. #pragma mark CONSTANTS
  53. #endif
  54.                 
  55. /*
  56. ** CONSTANTS
  57. */
  58.  
  59. #define    mPICTAnimationBaseID        128
  60. #define    mPICTAnimationNumberOfFaces    40
  61.  
  62. #if 0
  63. #pragma mark GLOBALS
  64. #endif
  65.                 
  66. /*
  67. ** GLOBALS
  68. */
  69.  
  70.  
  71. typedef struct iTQ3ADErrorModule
  72. {
  73.     long        drewHeaders;
  74.     PicHandle    wwwAddressPICT;
  75.     TPICTSprite    *sprite;
  76.     CGrafPtr    destPort;
  77.     Rect        destRect;
  78.     
  79. } iTQ3ADErrorModule;
  80.  
  81.  
  82.  
  83.     
  84. #if 0
  85. #pragma mark PRIVATE FUNCTION DECLARATIONS
  86. #endif
  87.                 
  88. /*
  89. ** PRIVATE FUNCTIONS
  90. */
  91. static    TQ3Status        iQ3ADErrorModule_ZeroOut(
  92.                             TQ3ADErrorModule    *ioModule);
  93.  
  94.  
  95. #if 0
  96. #pragma mark -
  97. #endif
  98.  
  99. /*===========================================================================*\
  100.  *
  101.  *    Routine:    Q3ADErrorModule_New()
  102.  *
  103.  *    Comments:    
  104.  *
  105. \*===========================================================================*/
  106.  
  107. TQ3ADErrorModule **Q3ADErrorModule_New(GMParamBlockPtr params)
  108. {
  109.     TQ3Status    status = kQ3Success;
  110.                 
  111.     TQ3ADErrorModule **outModule;
  112.     
  113.     Rect    monitorRect;
  114.     Rect    rotatingQD3DRect;
  115.     long    halfWidth, halfHeight;
  116.     
  117.     #define    mRotatingQD3D_Width        256
  118.     #define    mRotatingQD3D_Height    256
  119.  
  120.     assert(params);
  121.     
  122.     mBailIfNULL_(outModule = (TQ3ADErrorModule **)NewHandle(sizeof(TQ3ADErrorModule)));
  123.     HLock((Handle) outModule);
  124.         
  125.     mBailIfNot_(iQ3ADErrorModule_ZeroOut(*outModule));
  126.  
  127.     /*
  128.     **    Set up the destination rect
  129.     */
  130.     
  131.     /*
  132.     **    Make a base rect which is normalized and which has the dimensions
  133.     **    that we want
  134.     */
  135.     SetRect(
  136.         &rotatingQD3DRect,
  137.         0,
  138.         0,
  139.         mRotatingQD3D_Width - 1,
  140.         mRotatingQD3D_Height - 1);
  141.     
  142.     /*
  143.     **    Find out the optimal monitor to place it
  144.     */
  145.     
  146.     monitorRect    =    Q3ADUtility_GetRectOfBestMonitor(params->monitors);
  147.     
  148.     /*
  149.     **    Find the center of that monitor
  150.     */
  151.     halfWidth    =    (monitorRect.right    - monitorRect.left)    * 0.5;
  152.     halfHeight    =    (monitorRect.bottom    - monitorRect.top)    * 0.5;
  153.  
  154.     /*
  155.     **    place our rect there
  156.     */
  157.     OffsetRect(
  158.         &rotatingQD3DRect,
  159.         halfWidth - (mRotatingQD3D_Width / 2),
  160.         halfHeight - (mRotatingQD3D_Height / 2));
  161.  
  162.  
  163.     /*
  164.     **    We align this on byte boundaries because CopyBits can blit it faster.
  165.     **    We do this so that if anything, it shrinks the rect a bit to
  166.     **    make sure it stays on the screen.
  167.     */
  168. /*    SetRect(
  169.         &alignedRect,
  170.         rotatingQD3DRect.left    % kLongSize,
  171.         kLongSize - (rotatingQD3DRect.top    % kLongSize),
  172.         kLongSize - (rotatingQD3DRect.right    % kLongSize),
  173.         rotatingQD3DRect.bottom    % kLongSize);
  174. */                
  175.  
  176.  
  177.     mBailIfNULL_((**outModule).sprite    = PICTSprite_New(
  178.                     mPICTAnimationBaseID,
  179.                     mPICTAnimationNumberOfFaces,
  180.                     0,
  181.                     (CGrafPtr)params->qdGlobalsCopy->qdThePort,
  182.                     &rotatingQD3DRect));
  183.  
  184.     (**outModule).destRect    =    monitorRect;
  185.     (**outModule).destPort    =    (CGrafPtr)params->qdGlobalsCopy->qdThePort;
  186.     
  187.     /*
  188.     **    HTTP://QUICKDRAW3D.APPLE.COM
  189.     */    
  190.  
  191. /*    mBailIfNULL_(currentPicture    =    GetPicture(outPICTSprite->basePictureID));
  192.     
  193.     currentPicture_Height    =    (**currentPicture).picFrame.bottom -
  194.                                 (**currentPicture).picFrame.top;
  195.     currentPicture_Width    =    (**currentPicture).picFrame.right -
  196.                                 (**currentPicture).picFrame.left;
  197. */                                    
  198. bail:
  199.     
  200.     if (status == kQ3Failure)
  201.         if(outModule) {
  202.             Q3ADErrorModule_Dispose(outModule);
  203.             outModule    = NULL;
  204.         }
  205.     
  206.     return outModule;
  207. }
  208.  
  209.  
  210.  
  211. /*===========================================================================*\
  212.  *
  213.  *    Routine:    Q3ADErrorModule_Dispose()
  214.  *
  215.  *    Comments:    
  216.  *
  217. \*===========================================================================*/
  218.  
  219. TQ3Status Q3ADErrorModule_Dispose(TQ3ADErrorModule **inModule)
  220. {
  221.     assert(inModule);
  222.     
  223.     if ((**inModule).sprite)
  224.         PICTSprite_Dispose((**inModule).sprite);
  225.         
  226.     if ((**inModule).wwwAddressPICT)
  227.         ReleaseResource((Handle)(**inModule).wwwAddressPICT);
  228.         
  229.     DisposeHandle((Handle)inModule);
  230.     
  231.     return kQ3Success;
  232. }
  233.  
  234.  
  235.  
  236. /*===========================================================================*\
  237.  *
  238.  *    Routine:    Q3ADErrorModule_Draw()
  239.  *
  240.  *    Comments:    
  241.  *
  242. \*===========================================================================*/
  243.  
  244. TQ3Status Q3ADErrorModule_Draw(
  245.             TQ3ADErrorModule *inModule)
  246. {
  247.     TQ3Status    status            =    kQ3Success;
  248.     static long    lastTickCount    = 0;
  249.     long        currentTicks    = TickCount();
  250.     
  251.     
  252.     
  253.     if (currentTicks > lastTickCount + 2)
  254.     {
  255.         PICTSprite_Draw(inModule->sprite);
  256.         lastTickCount    = currentTicks;
  257.     }
  258. bail:
  259.  
  260.     return status;
  261. }
  262.  
  263.  
  264.  
  265. /*===========================================================================*\
  266.  *
  267.  *    Routine:    iQ3ADErrorModule_ZeroOut()
  268.  *
  269.  *    Comments:    
  270.  *
  271. \*===========================================================================*/
  272.  
  273. TQ3Status iQ3ADErrorModule_ZeroOut(TQ3ADErrorModule *inModule)
  274. {
  275.     assert(inModule);
  276.         
  277.     inModule->drewHeaders    = FALSE;
  278.     inModule->sprite        = NULL;
  279.     inModule->destPort        = NULL;
  280.     
  281.     inModule->wwwAddressPICT    = NULL;
  282.     
  283.     inModule->destRect.top        =
  284.     inModule->destRect.bottom    =
  285.     inModule->destRect.left        =
  286.     inModule->destRect.right    = 0;
  287.     
  288.     return kQ3Success;
  289. }
  290.  
  291.  
  292.  
  293.